package com.chapter16.ThreadMethod;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        C1 c1 = new C1();
        Thread thread = new Thread(c1);
        for (int i = 1; i <= 10; i++){
            System.out.println("hi " + i);
            if (i == 5){
                thread.start();
                thread.join();
            }
            Thread.sleep(1000);
        }
        System.out.println("主线程结束");
    }
}

class C1 implements Runnable {

    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println("hello " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("子线程结束");
    }
}
